package cn.com.se.sharepictrue.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.List;

import cn.com.se.sharepictrue.R;
import cn.com.se.sharepictrue.bean.MineCommentBean;
import cn.com.se.sharepictrue.business.ImageLoader;
import cn.com.se.sharepictrue.quickadapter.BaseAdapterHelper;
import cn.com.se.sharepictrue.quickadapter.MultiViewTypeSupport;
import cn.com.se.sharepictrue.quickadapter.QuickAdapter;
import cn.com.se.sharepictrue.utils.StringUtils;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2015/12/17.
 */
public class MineCommentListAdapter extends QuickAdapter<MineCommentBean> {

    private Context mContext;

    public MineCommentListAdapter(Context context, int layoutResId) {
        super(context, layoutResId);
        mContext = context;
    }

    public MineCommentListAdapter(Context context, int layoutResId, List<MineCommentBean> data) {
        super(context, layoutResId, data);
        mContext = context;
    }

    public MineCommentListAdapter(Context context, List<MineCommentBean> data, MultiViewTypeSupport<MineCommentBean> multiViewTypeSupport) {
        super(context, data, multiViewTypeSupport);
        mContext = context;
    }

    @Override
    protected void convert(final BaseAdapterHelper helper, final MineCommentBean item) {
        helper.setText(R.id.tv_mine_comment_name, item.getUserName());
        helper.setText(R.id.tv_mine_comment_time, item.getAddTime());
        helper.setText(R.id.tv_mine_comment_content, item.getComment());
        helper.setText(R.id.tv_mine_comment_sayhi, item.getShare().getShareContent());
        CircleImageView avatar = helper.getView(R.id.civ_other_user_avatar);
        if (!StringUtils.isEmpty(item.getShare().getAvatar()))
            ImageLoader.getInstance(mContext).load(avatar, item.getShare().getAvatar());
        else
            avatar.setImageResource(R.mipmap.bg_drawer);
        LinearLayout target = helper.getView(R.id.ll_mine_comment_share);
        target.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null)
                    mListener.shareClick(helper, item);
            }
        });
    }

    public void setCommentItemListener(CommentItemListener listener) {
        mListener = listener;
    }

    private CommentItemListener mListener;

    public interface CommentItemListener {
        void shareClick(BaseAdapterHelper helper, MineCommentBean item);
    }
}
